package com.ldgk.pim.client.view.gwt;

import com.google.gwt.maps.client.geom.LatLng;
import com.google.gwt.maps.client.overlay.Icon;
import com.ldgk.pim.client.presenter.MarkerPresenter;
import com.ldgk.pim.client.presenter.Presenter;
import com.ldgk.pim.client.view.MarkerView;
import com.ldgk.pim.client.view.components.PowerMarker;
import com.ldgk.pim.data.Place;

/**
 * MarkerView GWT implementation
 * @version 1.0
 *
 */
public class MarkerViewImpl implements MarkerView{
	/** Local result icon */
	private final Icon localResultIcon = Icon.newInstance("images/icons/blue-pushpin.png");
	private final Icon hospitalIcon = Icon.newInstance("images/icons/hospital.png");
	private final Icon schoolIcon = Icon.newInstance("images/icons/school.png");
	/** Marker presenter */
	private MarkerPresenter presenter;

	public MarkerViewImpl(){
		hospitalIcon.setShadowURL("images/icons/hospital-shadow.png");
		schoolIcon.setShadowURL("images/icons/school-shadow.png");
	}
	
	/**
	 * {@inheritDoc}
	 */
	public void setPresenter(Presenter presenter){
		this.presenter = (MarkerPresenter)presenter;
	}
	
	/**
	 * {@inheritDoc}
	 */
	public PowerMarker buildLocalResultMarker(Place dp){
		return PowerMarker.newInstance(dp, LatLng.newInstance(dp.getLat(), dp.getLng()),presenter.getMapView().getMapWidget(), localResultIcon, true);
	}
	
	/**
	 * {@inheritDoc}
	 */
	public PowerMarker buildDistributionPlaceMarker(Place dp){
		Icon icon = dp.getType() == Place.SCHOOL? schoolIcon:hospitalIcon;
		return PowerMarker.newInstance(dp, LatLng.newInstance(dp.getLat(), dp.getLng()),presenter.getMapView().getMapWidget(), icon , false);
	}
	
	
//	DistributionPlaceEvent evt = new DistributionPlaceEvent(dp, DistributionPlaceEvent.Type.EDIT);
//	Util.eventbus.fireEvent(evt);

}
